package com.iflysse.servlet.content;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.iflysse.pojo.ContentInfo;
import com.iflysse.service.ContentInfoService;

/**
 * Servlet implementation class AticlePage
 */
@WebServlet("/content/AticlePage_content")
public class AticlePage extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AticlePage() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String idStr = request.getParameter("id");
		int id = Integer.parseInt(idStr);
		ContentInfoService service=new ContentInfoService();
		ContentInfo info=service.findByContentId(id);
		int count = info.getCount();
		count = count + 1;
		info.setCount(count);
//		System.out.println(info);
		service.updateContent(info);
		request.setAttribute("content", info);
		request.getRequestDispatcher("/WEB-INF/views/home/newAticle.jsp").forward(request, response);
	}

}
